<template>
	<view>
		<!-- 总账户 -->
		<view v-if="role === constObj.ROLE_ADMIN">
			<admin-index v-if="tabIndex === 0"></admin-index>
			<admin-stat v-else-if="tabIndex === 1"></admin-stat>
			<admin-personal v-else-if="tabIndex === 2"></admin-personal>
		</view>
		
		<!-- 报价师 -->
		<view v-else-if="role === constObj.ROLE_QUOTER">
			<quoter-index v-if="tabIndex === 0"></quoter-index>
			<admin-stat v-else-if="tabIndex === 1"></admin-stat>
			<quoter-order v-else-if="tabIndex === 2"></quoter-order>
			<quoter-personal v-else-if="tabIndex === 3"></quoter-personal>
		</view>
		
		<!-- 门店公司 -->
		<view v-else-if="role === constObj.ROLE_COMPANY">
			<store-index v-if="tabIndex === 0" :role-info="roleInfo" @toTabbar="toTabbar"></store-index>
			<store-stat v-else-if="tabIndex === 1"></store-stat>
			<store-order v-else-if="tabIndex === 2"></store-order>
		</view>
		
		<!-- 门店店长 -->
		<view v-else-if="role === constObj.ROLE_STORE">
			<store-index v-if="tabIndex === 0" :role-info="roleInfo" @toTabbar="toTabbar"></store-index>
			<store-stat v-else-if="tabIndex === 1"></store-stat>
			<store-order v-else-if="tabIndex === 2"></store-order>
			<store-personal v-else-if="tabIndex === 3"></store-personal>
		</view>
		
		<!-- 门店店员 -->
		<view v-else-if="role === constObj.ROLE_CLERK">
			<store-index v-if="tabIndex === 0" :role-info="roleInfo" @toTabbar="clerkToOrder"></store-index>
			<store-order v-else-if="tabIndex === 1"></store-order>
			<store-personal v-else-if="tabIndex === 2"></store-personal>
		</view>
		
		<view>
			<u-tabbar
				:value="tabIndex"
				@change="changeTab"
				z-index="999"
			>
				<u-tabbar-item 
					v-for="(item,index) in menus" 
					:text="item.text" 
					:icon="item.icon"></u-tabbar-item>
			</u-tabbar>
		</view>
		<role-popup :show="show"  @close="show = false"></role-popup>
	</view>
</template>

<script>
	import adminIndex from "@/pages/admin/index.vue"
	import adminStat from "@/pages/admin/statistics.vue"
	import adminPersonal from "@/pages/admin/personal.vue"
	import quoterIndex from "@/pages/quoter/index.vue"
	import quoterOrder from "@/pages/quoter/order.vue"
	import quoterPersonal from "@/pages/quoter/personal.vue"
	import storeIndex from "@/pages/store/index.vue"
	import storeOrder from "@/pages/store/order.vue"
	import storePersonal from "@/pages/store/personal.vue"
	import storeStat from "@/pages/store/statistics.vue"
	
	export default {
		components: {
			adminIndex, adminStat, adminPersonal, 
			quoterIndex, quoterOrder, quoterPersonal,
			storeIndex, storeStat, storeOrder, storePersonal
		},
		data() {
			return {
				roleInfo: null,
				tabIndex: 0,
				show:false,
				role: null,
				constObj: this.$constant,
				menus: []
			}
		},
		created() {
			this.roleInit();
		},
		methods: {
			//店员跳转到订单
			clerkToOrder() {
				this.tabIndex = 1;
			},
			toTabbar(e) {
				this.tabIndex = e;
			},
			roleInit() {
				//报价师角色-菜单  店长菜单
				const roleQuoter = [
					{text: '工作台', icon:"home"},
					{text: '统计', icon:"file-text"},
					{text: '订单', icon:"order"},
					{text: '我的', icon:"account"}
				]
				//回收端管理员-菜单
				const roleAdmin = [
					{text: '工作台', icon:"home"},
					{text: '统计', icon:"file-text"},
					{text: '我的', icon:"account"}
				]
				// 公司菜单
				const companyMenu = [
					{text: '工作台', icon:"home"},
					{text: '统计', icon:"file-text"},
					{text: '订单', icon:"order"}
				]
				//店员菜单
				const clerkMenu = [
					{text: '工作台', icon:"home"},
					{text: '订单', icon:"order"},
					{text: '我的', icon:"account"}
				]
				
				uni.getStorage({
					key: this.$constant.ROLE_INFO_KEY,
					success: (res) => {
						this.roleInfo = res.data;
						this.role = res.data.role
						if(this.role === this.$constant.ROLE_ADMIN){
							this.menus = roleAdmin
						}else if(this.role === this.$constant.ROLE_QUOTER || this.role === this.$constant.ROLE_STORE){
							this.menus = roleQuoter
						}else if(this.role === this.$constant.ROLE_COMPANY) {
							this.menus = companyMenu
						}else if(this.role === this.$constant.ROLE_CLERK) {
							this.menus = clerkMenu
						}
						this.changeTab(0);
					},
					fail: (err) => {
						console.log(err)
						uni.navigateTo({
							url: "/pages/login/login"
						})
					}
				})
			},
			changeTab(e) {
				this.tabIndex = e;
				uni.setNavigationBarTitle({
					title: this.menus[e].text
				})
				uni.pageScrollTo({
					scrollTop: 0,
					duration: 100
				});
			}
		}
	}
</script>

<style>

</style>
